package com.ruanjian.api.utils;

import java.util.Date;

/**
 * @author shkstart
 * @create 2022-11-21 20:38
 */
public class DateUtil {

    /**
     * 获取当前时间
     * @return
     */
    public static Date getNowDate(){
        return new Date();
    }

    /**
     * 计算时间差
     * @param endDate 结束时间
     * @param nowDate 当前时间
     * @return
     */
    public static String getDatePoor(Date endDate, Date nowDate) {
        long nd = 1000 * 24 * 60 * 60;
        long nh = 1000 * 60 * 60;
        long nm = 1000 * 60;
        long ns = 1000;
        // 获得两个时间的毫秒时间差异
        long diff = endDate.getTime() - nowDate.getTime();
        // 计算差多少天
        long day = diff / nd;
        // 计算差多少小时
        long hour = diff % nd / nh;
        // 计算差多少分钟
        long min = diff % nd % nh / nm;
        // 计算差多少秒//输出结果
        long sec = diff % nd % nh % nm / ns;
        String difference = day + "天" + hour + "小时" + min + "分" + sec + "秒";
        if (day == 0){
            difference = hour + "小时" + min + "分" + sec + "秒";
            if (hour == 0){
                difference = min + "分" + sec + "秒";
                if (min == 0)
                    difference = sec + "秒";
            }
        }
        return difference;
    }

}
